<?php

namespace app\models;

use think\Model;

/**
 * 区域模型
 * User: Small Y
 * Date: 2017/03/13
 * @package app\models
 */
class RegionalModel extends Model
{
	protected $table = 'edu_regional';

	/**
	 * 区域列表
	 * modify by Small Y
	 *
	 * @param $param
	 * @return array
	 * @throws \think\exception\DbException
	 */
	public function getRegionalLists($param)
	{
		$page = isset($param['page']) ? (int) $param['page'] : 1;
		$listRows = isset($param['limit']) ? (int) $param['limit'] : 10;
		$where = [];
		if (isset($param['regional_name']) && '' !== $param['regional_name']) {
			$where['regional_name'] = ['like', $param['regional_name'].'%'];
		}
		if (isset($param['status']) && '' !== $param['status']) {
			$where['status'] = $param['status'];
		}
		if(get_current_type() == 2){
			$where['company_id'] = get_current_company_id();
		}
		$listData = self::where($where)
			->paginate($listRows, false, ['page' => $page])
			->toArray();
		if (!empty($listData)) {
			foreach ($listData['data'] as &$item) {
				$item['status_text'] = (1 === $item['status']) ? '启用' : '禁用';
				$item['company_name'] = CompanyModel::get($item['company_id'])['company_name'];
			}
		}

		return $listData;
	}

}
